﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NCalculator.Operations
{
    [Serializable()]
    public class DivisionNode : OperationNode
    {
        public DivisionNode()
        {
            _priority = 3;
        }

        /// <summary>
        /// Evaluation division
        /// </summary>
        /// <returns>0 if error</returns>
        public override double Evaluation()
        {
            // checking if division is correct
            if (0 == _right.Evaluation())
            {
                throw new Exception(NCalculator.Properties.Resources.DividedByZero);
            }

            if ((_left != null) && (_right != null))
            {
                return _left.Evaluation() / _right.Evaluation();
            }
            else
                return 0;
        }

        public override string ToString()
        {
            if ((_left == null) || (_right == null))
                return " / ";
            else
            {
                //return string.Format("{0} / {1} ", _left.Evaluation().ToString(), _right.Evaluation().ToString());
                return " / ";
            }
        }
    }
}
